package com.example.reagent_management.room.dao;

import com.example.reagent_management.ui.message.pojo.Message;

import java.util.List;

import androidx.paging.PagingSource;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Transaction;

@Dao
public interface MessageDao {
    @Insert
    Long insertMessage(Message message);

    @Query("select * from message where type = :type")
    List<Message> getTypeMessage(int type);

    @Query("select * from message order by message_id desc")
    PagingSource<Integer, Message> getAllMessage();

    //count(xx)可统计提醒次数
    @Query("select message_id from message where type=:type and remindId=:remindId")
    Long getRemind(int type, Long remindId);

    @Query("delete from message where type = 0")
    void deleteAll();

    @Query("delete from message where time < datetime('now', 'localtime', '-31 days')")
    void cleanMessage();
}
